#include<iostream>
using namespace std;

int main()
{
    int i,j,k,n,a;
    int maxs,sum;
    cin>>n;
    cin>>maxs;
    sum=maxs;
    for(i=2;i<=n;i++){
        scanf("%d",&a);
        sum=sum<0?a:sum+a;
        maxs=max(maxs,sum);
    }
    cout<<maxs;
    return 0;
}

